package com.zfjt.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.BrabchBean;
import com.zfjt.entity.ReturnBean;
import com.zfjt.service.BrabchService;

/**
 * 查询所有网点（注册时使用选择网点）
 * @author xk
 * @version 1.0
 * @date 2017年3月29日
 */
@Controller
public class BrabchController {

	//返回对象
	private ReturnBean mReturn;
	
	private Map<String, String> fhdata;
		
	@Autowired
	private BrabchService mBrabch;
	
	@RequestMapping(value="00003")
	@ResponseBody
	public ReturnBean Brabch(HttpSession hseesion){
		mReturn = new ReturnBean();
		fhdata = new HashMap<>();
		//传过来的参数
		String data =  (String) hseesion.getAttribute("data");
		if (data.equals(InterfaceDefinition.IStatusCode.TOKEN_FAILURE)) {
			mReturn.setPortnum("00003");
			mReturn.setCode("001");
			fhdata.put("error", "TOKEN_ERROR");
			mReturn.setData(JSON.toJSONString(fhdata));
		}else{
			List<BrabchBean> mData = mBrabch.selectAll();
			mReturn.setCode("000");
			mReturn.setPortnum("00003");
			mReturn.setData(JSON.toJSONString(mData));
		}
		return mReturn;
	}	
}
